﻿using EYWeb.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EYWeb.Frontend.App_Start.Handler
{
    public class LoginAttribute:AuthorizeAttribute
    {
        public bool Ignore = true;

        public LoginAttribute(bool ignore=true)
        {
            Ignore = ignore;
        }

        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            //base.OnAuthorization(filterContext);
            if(Ignore==false)
            {
                return;
            }
            if(OperatorProvider.Provider.GetCurrent()==null)
            {
                WebHelper.WriteCookie("login_error", "Overdue");
                filterContext.HttpContext.Response.Write("<script>top.location.href='/Login/Index';</script>");
                return;
            }


        }

    }
}